package day02;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class GMethodTest {
    public static <E> ArrayList<E> removeDuplicates(ArrayList<E> list) {
        Set<E> set = new HashSet<>(list);//HashSet函数去重
        return new ArrayList<>(set);
    }

    public static <E extends Comparable<E>> E max(E[] list) {
        if (list.length == 0) {
            System.out.println("list is empty");
            throw new IllegalArgumentException();
        }
        E max = list[0];
        for (int i = 1; i < list.length; i++) {
            if (max.compareTo(list[i]) < 0) {
                max = list[i];
            }
        }
        return max;
    }
}

class Circle implements Comparable<Circle> {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public int compareTo(Circle circle) {
        if (this.radius < circle.radius) {
            return -1;
        } else if (this.radius > circle.radius) {
            return 1;

        } else {
            return 0;
        }
    }

    @Override
    public String toString() {
        return "Circle radius: " + radius;
    }
}
